<?php
/**
 * Pes for PHP 5.3+
 *
 * Copyright (c) 2013 phpeskill.com (http://www.pescms.com)
 *
 * For the full copyright and license information, please view
 * the file LICENSE.md that was distributed with this source code.
 */
namespace Model\Admin;

/**
 * 选项模型
 * @author LazyPHP
 * @version 1.0
 */
class OptionModel extends CommonModel {
    
    /**
     * 获取系统的配置选项
     * @param type $value 查找的值
     * @param type $type 查找的类型|默认为ID
     * @return boolean 提交参数为空时，返回二维数组。参数不为空则返回一维数组。没有结果则返回false;
     */
    public static function getOption($value="", $type="id"){
        return self::GetTableContent($value, $type, 'option');
    }
    
    /**
     * 获取系统字段表单类型
     * @param type $type 匹配表单
     * @return str 返回一个配置好的表单
     */
    public static function formtype($type = ''){
        $db = self::db('option');
        $result = $db->where('id = 8 and option_range = "Miscellaneous"')->find();
        $formList = json_decode($result['value'], true);
        $str = '';
        foreach ($formList as $key => $value){
            if($type == $key){
                $str .= '<option value="'.$key.'" selected="selected">'.$value.'</option>';
            }else{
                $str .= '<option value="'.$key.'">'.$value.'</option>';
            }
        }
        
        return $str;
    }
    
    /**
     * 获取网站设置信息
     * @return type 返回数组
     */
    public static function getSiteSetting(){
        $db = self::db('option');
        $result = $db->where('option_range = "setting"')->select();
        return $result;
    }
}